package com.think.archive.controller.api;

import com.think.archive.common.ResultBean;
import com.think.archive.model.SysDept;
import com.think.archive.model.SysFunc;
import com.think.archive.service.SysFuncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api")
public class FuncController {

    @Autowired
    SysFuncService funcService;

    @GetMapping("funcs")
    public ResultBean getFuncs(@RequestParam(value = "funcCode", required = false) String funcCode){
        List<SysFunc> funcs=funcService.findNextLevelFunc(funcCode);
        return ResultBean.createResultBySuccess(funcs);
    }

    @PostMapping("saveFunc")
    public ResultBean saveFunc(SysFunc func){
        return ResultBean.createResultBySuccess(funcService.insertOrUpdateFunc(func));
    }

    @PostMapping("deleteFunc")
    public ResultBean deleteFunc(int id){
        return ResultBean.createResultBySuccess(funcService.deleteFunc(id));
    }

    @RequestMapping("func/state/change")
    public ResultBean changeStatusFunc(int id ,String status){
        int res=funcService.changeStatusFunc(id,status);
        return ResultBean.createResultBySuccess(res);
    }




}
